package adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.parkcar.R;

import java.util.ArrayList;
import java.util.List;

import Modle.SimpleCommunityBean;

/**
 * Created by Administrator on 2016/3/19.
 */
public class CommunityAdapter extends BaseAdapter{
    private Context mContext;
    private List<SimpleCommunityBean> mData = new ArrayList<>();
    public CommunityAdapter(Context mContext){
        this.mContext = mContext;
    }
    @Override
    public int getCount() {
        return mData.size();
    }

    @Override
    public Object getItem(int i) {
        return mData.get(i);
    }

    @Override
    public long getItemId(int i) {
        return mData.get(i).getId();
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder mHolder;
        if(view==null){
            mHolder = new ViewHolder();
            view = LayoutInflater.from(mContext).inflate(R.layout.adapter_community,null);
            mHolder.addressTv = (TextView) view.findViewById(R.id.addressTv);
            mHolder.titleTv = (TextView) view.findViewById(R.id.titleTv);
            view.setTag(mHolder);
        }else{
            mHolder = (ViewHolder) view.getTag();
        }
        mHolder.titleTv.setText(mData.get(i).getName());
        mHolder.addressTv.setText(mData.get(i).getAddress());
        return view;
    }
    class ViewHolder{
        TextView titleTv;
        TextView addressTv;
    }
    public void setData(List<SimpleCommunityBean> mData){
        this.mData = mData;
        notifyDataSetChanged();
    }

}
